package com.parking.carsystem.parkingchargesystem.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.parking.carsystem.parkingchargesystem.R;
import com.parking.carsystem.parkingchargesystem.common.Constant;
import com.parking.carsystem.parkingchargesystem.module.MouthModel;
import com.parking.carsystem.parkingchargesystem.module.RechargeRecoedModel;

import butterknife.BindView;
import ttyy.com.recyclerexts.base.EXTRecyclerAdapter;
import ttyy.com.recyclerexts.base.EXTViewHolder;

public class RechargeRecordActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.record_list)
    RecyclerView recordList;
    private EXTRecyclerAdapter<RechargeRecoedModel.RowsBean> recordAdapter;
    @Override
    protected int getContentViewId() {
        return R.layout.activity_record;
    }

    @Override
    public void initView() {
        back.setVisibility(View.VISIBLE);
        text.setText("充值记录");
    }

    @Override
    public void initData() {
        recordList.setLayoutManager(new LinearLayoutManager(this));
        recordAdapter = new EXTRecyclerAdapter<RechargeRecoedModel.RowsBean>(R.layout.item_recharge_record) {
            @Override
            public void onBindViewHolder(EXTViewHolder extViewHolder, int i, RechargeRecoedModel.RowsBean rowsBean) {
                extViewHolder.setText(R.id.recharge,"+"+rowsBean.fee+"元");
                extViewHolder.setText(R.id.create_time,rowsBean.createTime);
            }
        };
        recordAdapter.setDatas(null);
        recordList.setAdapter(recordAdapter);
        getMemberList();
    }
    /**
     * 充值记录
     */
    private void getMemberList() {
        OkGo.<String>get(Constant.url + Constant.LISTACCOUNTDETAIL)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        RechargeRecoedModel mouthModel = gson.fromJson(response.body(), RechargeRecoedModel.class);
                        if (mouthModel.code==200) {
                            recordAdapter.setDatas(mouthModel.rows);
                            recordAdapter.notifyDataSetChanged();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {

                    }
                });
    }
}
